<?php
namespace api\modules\community_post\controllers;

use Yii;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;

use yii\filters\VerbFilter;
use yii\filters\AccessControl;

use base\YiiMobo;

/**
 * Site controller
 */
class IndexController extends \submodule\base\BaseSubmoduleApiController
{
	public $moduleid = 'community_post';
	
	public function init(){
	    parent::init();
	}
	

    public function actionIndex(){
		$data = $this->apiList(true);
		
		foreach($data['results'] as $k=>$v){
			$sql="SELECT a.`addtime`,a.`content`,b.`username`,b.`avatar` FROM {{%community_reply}} a left join {{%user}} b on a.`userid` = b.`userid` where a.`postid` = {$v['postid']} and a.`status` = 1 order by a.`replyid` desc limit 0,3";
			
			$replys = Yii::$app->db->createCommand($sql)->queryAll();
			$data['results'][$k]['replylist'] = $replys;
		}
		
		self::echojson($data);
	}
	
	
	public function actionView(){
		$this->apiView();
		
	}
	
	
	public function actionCreate(){
		$this->apiCreate();
	}
	
	public function actionUpdate(){
		$this->apiUpdate();
	}
}
